#ifndef QBCIOPACITYRENDER_H
#define QBCIOPACITYRENDER_H

#include <QPainter>
#include <QBciRender>
#include <QElapsedTimer>
#include <QSharedPointer>

/*!
 * \brief The WaveGenerator class 用来产生特定沿时间变化的波形
 */
class QWaveGeneratorInterface {
public:
  // 用于启动计时器，在程序开始前调用
  static void init();
  // 重置时间至0
  static void reset();

  QWaveGeneratorInterface();
  virtual ~QWaveGeneratorInterface() {}

  // 获得当前函数值
  double value();

protected:
  // 子类需要重写该函数
  // 该函数在获取value()时被调用
  // 接收当前时间并且返回合适的数值
  virtual double funcOfTime(const long long &t) = 0;

private:
  static QElapsedTimer mTimer;
};

/*!
 * \brief The QSinWaveGenerator class 产生正弦波
 *
 * 正弦波的值在[0, 1]区间
 */
class QSinWaveGenerator : public QWaveGeneratorInterface {
public:
  QSinWaveGenerator();
  virtual ~QSinWaveGenerator() {}

  // 设定频率
  void setFreq(const double &freq);
  // 设定初相位
  void setInitPhase(const double &phase);

protected:
  double funcOfTime(const long long &t) override;

private:
  double mFreq = 1;

  long long mTimeBias = 0;
  long long mPrePeriod = 1000;
  bool mNeedUpdate = true;
};


class QBciOpacityRender : public QBciRender
{
public:
    QBciOpacityRender();

    typedef QSharedPointer<QSinWaveGenerator> SinWaveGenP;

protected:
    virtual void stylePaint(QPainter* painter) override;

    virtual void setWaveType(WaveType wave) override;

    virtual void setEnableWave(const bool &flag, const int &ID = 0) override;

    virtual void setFreq(const int &ID, const double &freq) override;

    virtual void startFlick() override;

    virtual void stopFlick() override;

private:
    // 波形生成器
    SinWaveGenP Wave = nullptr;
    bool EnableWave = false;

};

#endif // QBCIOPACITYRENDER_H
